/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 2 -*- */
/**
* @file doubleengine.cpp
* 
* Library for easy managing the power of two engines.
* 
* @author Miguel Ángel Vílchez López 2010 <sacra@openmatica.es>
*
* Codigo is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* Codigo is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "doubleengine.hpp"
#include "softservo.cpp"

CMDoubleEngine::CMDoubleEngine(int acceleration=1,int min=-100,int max=100):engine_left(acceleration,min,max),engine_right(acceleration,min,max)
{}

CMDoubleEngine::~CMDoubleEngine()
{}

void CMDoubleEngine::go(int value)
{
	this->engine_left.setEnd(value);
	this->engine_right.setEnd(value);
}

void CMDoubleEngine::goForwardLeft(int diff)
{
	this->engine_left.setEnd(this->engine_right.getNow()-diff);
}
		
void CMDoubleEngine::goForwardRight(int diff)
{
	this->engine_right.setEnd(this->engine_left.getNow()-diff);
}

void CMDoubleEngine::goBackwardLeft(int diff)
{
	this->engine_left.setEnd(this->engine_right.getNow()+diff);
}
	
void CMDoubleEngine::goBackwardRight(int diff)
{
	this->engine_right.setEnd(this->engine_left.getNow()+diff);
}

void CMDoubleEngine::turnLeft(int diff)
{
	this->engine_left.setEnd((-1)*(int)(diff/2));
	this->engine_right.setEnd((int)(diff/2));
}

void CMDoubleEngine::turnRight(int diff)
{
	this->engine_left.setEnd((int)(diff/2));
	this->engine_right.setEnd((-1)*(int)(diff/2));
}

void CMDoubleEngine::stop()
{
	this->engine_left.stop();
	this->engine_right.stop();
}

void CMDoubleEngine::update()
{
	this->engine_left.update();
	this->engine_right.update();
}

int CMDoubleEngine::getLeftEngine()
{
	return this->engine_left.getNow();
}

int CMDoubleEngine::getRightEngine()
{
	return this->engine_right.getNow();
}
